//
//  MyTableViewController.m
//  13_Work jianShu
//
//  Created by dllo on 16/8/1.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "MyTableViewController.h"
#define kTableView @"reuse"
#import "MyTableViewCell.h"
#import "YHCycleImage.h"
#define WIDTH self.tableView.frame.size.width
#define HEUGHT self.tableView.frame.size.height
#import "CreateButton.h"
#import "SecTableViewCell.h"
#define secKtableView @"secReuse"

@interface MyTableViewController ()
@property (nonatomic, strong) UIView *headView;
@property (nonatomic, strong) NSArray *picArray;
@property (nonatomic, strong) UIScrollView *buttonScrollView;


@end

@implementation MyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    [self createCycleView];
    [self createButtonView];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)createCycleView {
    self.picArray = [NSArray array];
    self.headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 240)];
    self.tableView.tableHeaderView = self.headView;
    YHCycleImage *cycle = [[YHCycleImage alloc] initWithFrame:CGRectMake(0, 40, self.tableView.frame.size.width, 200)];
    self.picArray = @[@"newsPic1", @"newsPic2", @"newsPic3", @"newsPic4"];
    [cycle createImagesWithArray:self.picArray];
    [self.tableView.tableHeaderView addSubview:cycle];
}

- (void)createButtonView {
    self.buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 40)];
    self.buttonScrollView.contentSize = CGSizeMake(1.5 * WIDTH, 0);
    self.buttonScrollView.backgroundColor = [UIColor yellowColor];
    [self.tableView.tableHeaderView addSubview:self.buttonScrollView];
    
    UIButton *button1 = [CreateButton createButton1Frame:CGRectMake(5, 5, 40, 30)];
    [button1 setTitle:@"热门" forState:UIControlStateNormal];
    [self.buttonScrollView addSubview:button1];
    
    UIButton *button2 = [CreateButton createButton1Frame:CGRectMake(70, 5, 70, 30)];
    [button2 setTitle:@"新上榜" forState:UIControlStateNormal];
    [self.buttonScrollView addSubview:button2];
    
    UIButton *button3 = [CreateButton createButton1Frame:CGRectMake(160, 5, 40, 30)];
    [button3 setTitle:@"日报" forState:UIControlStateNormal];
    [self.buttonScrollView addSubview:button3];
    
    UIButton *button4 = [CreateButton createButton1Frame:CGRectMake(220, 5, 70, 30)];
    [button4 setTitle:@"新上榜" forState:UIControlStateNormal];
    [self.buttonScrollView addSubview:button4];
    
    UIButton *button5 = [CreateButton createButton1Frame:CGRectMake(310, 5, 70, 30)];
    [button5 setTitle:@"新上榜" forState:UIControlStateNormal];
    [self.buttonScrollView addSubview:button5];
    
    UIButton *button6 = [CreateButton createButton1Frame:CGRectMake(410, 5, 70, 30)];
    [button6 setTitle:@"新上榜" forState:UIControlStateNormal];
    [self.buttonScrollView addSubview:button6];
    
    UIButton *button7 = [CreateButton createButton1Frame:CGRectMake(500, 5, 70, 30)];
    [button7 setTitle:@"新上榜" forState:UIControlStateNormal];
    [self.buttonScrollView addSubview:button7];
    
    UIButton *button8 = [CreateButton createButton1Frame:CGRectMake(590, 5, 70, 30)];
    [button8 setTitle:@"新上榜" forState:UIControlStateNormal];
    [self.buttonScrollView addSubview:button8];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 100;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row % 3 == 0) {
        SecTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:secKtableView];
        return cell;
    } else {
        MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableView];
        return cell;
    }
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
